#!/bin/bash 

createField()
{	 
	for ((i=0;i<100;i++))
		do
			arr[i]=" • ";
		done	
}

renderField()
#drawing the field (numbers first, then values in array)
{
	for ((row=0;row<12;row++));do
		if [ $row == 0 ];then
			echo "    0  1  2  3  4  5  6  7  8  9 ";		
		elif [ $row == 1 ];then
			echo "  -------------------------------";
		else
			for((col=0 ;col<11; col++));do
				if [ $col == 0 ];then					
					let temp=$row-2;
						echo -n "$temp |";
				else
					echo -n "${arr[10*(row-2)+(col-1)]}"
				fi
			done			
			echo ""
		fi
	done	
	echo ""
}

createField;

for arg in $@;do
	begin_raw=${arg:0:1}
	begin_col=${arg:1:1}
	end_raw=${arg:2:1}	
	end_col=${arg:3:1}
	
#checking if the input data correct
	if [[ "$arg" =~ ^[0-9]{4}$  ]] && [[ $begin_raw == $end_raw || $begin_col == $end_col ]];then
	
		for((i=$begin_raw;i <= $end_raw;i++));do
			for((j=$begin_col;j <= $end_col;j++));do
#putting a ship to the field
				arr[10*i+j]="███"; 
			done				
		done						
	else echo "Wrong input! Ship should be a line shaped."
	
	fi
done

renderField;

exit 0;
